class Solution
{
public:
    // 不使用字符串、64位整数
    int reverse(int x)
    {
        int reversed = 0;
        while (x != 0)
        {
            if (reversed < INT_MIN / 10 || reversed > INT_MAX / 10)
            {
                return 0;
            }
            int digit = x % 10;
            x /= 10;
            reversed = reversed * 10 + digit;
        }
        return reversed;
    }


    int reverseByString(int x)
    {
        if (x == INT_MIN || x == 0)
        {
            return 0;
        }
        bool minus = (x < 0);
        x = abs(x);
        string sx = to_string(x);
        std::reverse(sx.begin(), sx.end());
        long long result = stol(sx);
        if (result > INT_MAX)
        {
            return 0;
        }
        else
        {
            x = static_cast<int>(result);
        }
        if (minus)
        {
            x = -x;
        }
        return x;
    }
};
